﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading;

/*
Personal Assistant V2.0
http://personala.codeplex.com
*/
namespace Personal_Assistant
{
    class Program
    {
        PA _pa = new PA();

        static void Main(string[] args)
        {
            Program p1 = new Program();

            p1._pa.CreateReqDirs();
            
            Console.Title = "Personal Assistant";
            Console.WindowHeight = 30;
            Console.WindowWidth = 90;
            Console.BackgroundColor = ConsoleColor.DarkGreen;
            Console.ForegroundColor = ConsoleColor.White;
            Console.Clear();
            
            Console.CursorLeft = 31;
            Console.WriteLine("WELCOME TO PERSONAL ASSISTANT");
            Console.CursorLeft = 35;
            Console.WriteLine("PRESS ENTER TO PROCEED");
            Console.ReadLine();
            
            List<string> recentevt = p1._pa.CheckToday();
            if (recentevt.Count != 0)
            {
                int x = 0;
                foreach (var data in recentevt)
                {
                    string path = (@"PersonalAssistant\Appointments\" + data.Split('\\')[2]).Split('.')[0];
                    
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("ALERT! ALERT!! ALERT!!!", 800);
                    Console.ForegroundColor = ConsoleColor.White;

                    if (x == 0)
                        Console.WriteLine("\nYou have an appointment today (" + data.Split('\\')[2].Split('.')[0] + ");");
                    else
                        Console.WriteLine("\nYou have another appointment today (" + data.Split('\\')[2].Split('.')[0] + ");");

                    p1._pa.WriteYellowText("Subject: \t\t"); Console.WriteLine(File.ReadAllText(path + @"\Subject.txt"));
                    p1._pa.WriteYellowText("Location: \t\t"); Console.WriteLine(File.ReadAllText(path + @"\Location.txt"));
                    p1._pa.WriteYellowText("Date of Appointment: \t"); Console.WriteLine(File.ReadAllText(path + @"\Date_of_Appointment.txt"));
                    p1._pa.WriteYellowText("Time of Appointment: \t"); Console.WriteLine(File.ReadAllText(path + @"\Time_of_Appointment.txt"));
                    p1._pa.WriteYellowText("Notes: \t\t\t"); Console.WriteLine(File.ReadAllText(path + @"\Notes.txt"));
                    Console.WriteLine();

                    x++;
                }
            }

            p1.MainMenu();
        }

        private void MainMenu()
        {
            Console.WriteLine("\nPERSONAL ASSISTANT MENU \nA - Contacts \nB - Appointments \nC - Calendar \nD - About \nE - Exit");
            string ans = Console.ReadLine();
            ans = ans.ToUpper();
            while (!_pa.IsValid(ans, 5))
            {
                Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A, B , C, D or E");
                ans = Console.ReadLine();
                ans = ans.ToUpper();
            }

            switch (ans)
            {
                case "A": Contacts(); break;
                case "B": Appointments(); break;
                case "C": Calendar(); break;
                case "D": About(); break;
                case "E": _pa.ExitApp(); break;
            }
        }

        private void Contacts()
        {
            Console.WriteLine("\nPERSONAL ASSISTANT CONTACT MENU \nA - New \nB - Open \nC - View all \nD - Main Menu");
            string ans = Console.ReadLine();
            ans = ans.ToUpper();
            while (!_pa.IsValid(ans, 5))
            {
                Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A, B , C, D or E");
                ans = Console.ReadLine();
                ans = ans.ToUpper();
            }

            switch (ans)
            {
                case "A": Console.WriteLine(); AddContacts(); break;
                case "B": OpenContacts(); break;
                case "C": ViewAllContacts(); break;
                case "D": MainMenu(); break;
                case "E": _pa.ExitApp(); break;
            }
        }

        private void OpenContacts()
        {
            Console.CursorLeft = 37;
            _pa.WriteYellowText("OPEN CONTACT MENU");
            Console.Write("\n\nEnter the name used to save the contact: ");
            string savname = _pa.ReadValidComp();
            string upath = @"PersonalAssistant\Contacts\";

            savname = savname.Replace(" ", "");

            while (savname != "0" && !Directory.Exists(upath + savname))
            {
                Console.WriteLine("\nNAME DOESN'T EXIST. PLEASE ENTER A VALID NAME OR ENTER 0 TO EXIT AND USE VIEW ALL");
                savname = _pa.ReadValidComp();
            }

            if (savname == "0")
                Contacts();
            else
            {
                if (Directory.Exists(upath + savname))
                {
                    string fullname = File.ReadAllText(upath + savname + @"\First_Name.txt") + " " + File.ReadAllText(upath + savname + @"\Last_Name.txt");
                    Console.WriteLine("\nContact (" + fullname + ") Found \nWhat do you want to do? \nA - Edit \nB - View \nC - Delete \nD - Back to Main Menu");
                    string ac = _pa.ReadValidComp();
                    ac = ac.ToUpper();

                    while (!_pa.IsValid(ac, 4))
                    {
                        Console.WriteLine("\nYou have selected an invalid value. Please enter either A, B, C or D");
                        ac = _pa.ReadValidComp();
                    }

                    switch (ac)
                    {
                        case "A": EditContact(upath + savname + @"\"); break;
                        case "B": ViewContact(upath + savname + @"\"); break;
                        case "C": DeleteContact(upath + savname + @"\"); break;
                        case "D": MainMenu(); break;
                    }
                }
            }
        }

        private void ViewContact(string path)
        {
            Console.CursorLeft = 33;
            _pa.WriteYellowText("CONTACT DETAILS (" + path.Split('\\')[2] + ")");
            Console.Write("\n\nFirst Name: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"First_Name.txt"));
            Console.Write("\nLast Name: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Last_Name.txt"));
            Console.Write("\nMiddle Name: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Middle_Name.txt"));
            Console.Write("\nAddress: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Address.txt"));
            Console.Write("\nState: \t\t");
            _pa.WriteYellowText(File.ReadAllText(path + @"State.txt"));
            Console.Write("\nCountry: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Country.txt"));
            Console.Write("\nGender: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Gender.txt"));
            Console.Write("\nDate of Birth: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Date_of_Birth.txt"));
            Console.Write("\nPhone Number: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Phone_Number.txt"));
            Console.Write("\nEmail Address: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Email_Address.txt"));

            Console.WriteLine();
            Contacts();
        }

        private void DeleteContact(string path)
        {
            Console.WriteLine("\nDo you really want to delete this contact? \nA - Yes \nB - No");
            string inp = _pa.ReadValidComp();
            inp = inp.ToUpper();
            while (!_pa.IsValid(inp, 2))
            {
                Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A or B");
                inp = Console.ReadLine();
                inp = inp.ToUpper();
            }

            switch (inp)
            {
                case "A": Directory.Delete(path, true); Console.WriteLine("\n*****************************\nCONTACT DELETED SUCCESFULLY\n*****************************"); MainMenu(); break;
                case "B": Console.WriteLine("\n*****************************\nDELETE CONTACT MENU EXITED\n*****************************"); MainMenu(); break;
            }
        }

        private void ViewAllContacts()
        {
            Console.CursorLeft = 37;
            _pa.WriteYellowText("ALL CONTACT NAMES\n\n");
            if (!Directory.EnumerateFileSystemEntries(@"PersonalAssistant\Contacts").Any())
            {
                Console.WriteLine("\nNO SAVED CONTACTS FOUND");
                MainMenu();
            }
            else
            {
                foreach (string f in Directory.GetDirectories(@"PersonalAssistant\Contacts"))
                {
                    string names = f.Split('\\')[2];
                    names = names.First().ToString().ToUpper() + names.Substring(1);
                    Console.WriteLine(names);
                }

                Console.WriteLine("\nDo you want to open a contact? \nA - Yes \nB - No");
                string inp = _pa.ReadValidComp();
                inp = inp.ToUpper();
                while (!_pa.IsValid(inp, 2))
                {
                    Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A or B");
                    inp = Console.ReadLine();
                    inp = inp.ToUpper();
                }

                switch (inp)
                {
                    case "A": OpenContacts(); break;
                    case "B": MainMenu(); break;
                }
            }
        }

        private void EditContact(string path)
        {
            Dictionary<string, string> fields = new Dictionary<string, string>();

            Console.CursorLeft = 37;
            _pa.WriteYellowText("EDIT CONTACT");
            Console.WriteLine("\nNOTE: Press ENTER at any field to skip editing\n      When entering date, ensure month and day always have two numbers. \n      Text shown in yellow indicates the existing data in that field");

            Console.Write("\nFirst Name: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "First_Name.txt"));
            Console.Write(") : ");
            string fname = Console.ReadLine();
            if (fname != "")
                fields.Add("First Name", fname);

            Console.Write("\nLast Name: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Last_Name.txt"));
            Console.Write(") : ");
            string lname = Console.ReadLine();
            if (lname != "")
                fields.Add("Last Name", lname);

            Console.Write("\nMiddle Name: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Middle_Name.txt"));
            Console.Write(") : ");
            string mname = Console.ReadLine();
            if (mname != "")
                fields.Add("Middle Name", mname);

            Console.Write("\nAddress: \n(");
            _pa.WriteYellowText(File.ReadAllText(path + "Address.txt"));
            Console.Write(") : ");
            string add = Console.ReadLine();
            if (add != "")
                fields.Add("Address", add);

            Console.Write("\nState: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "State.txt"));
            Console.Write(") : ");
            string state = Console.ReadLine();
            if (state != "")
                fields.Add("State", state);

            Console.Write("\nCountry: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Country.txt"));
            Console.Write(") : ");
            string country = Console.ReadLine();
            if (country != "")
                fields.Add("Country", country);

            Console.Write("\nGender: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Gender.txt"));
            Console.Write(") : ");
            string sex = _pa.ReadValidGender("EDIT");
            if (sex != "")
                fields.Add("Gender", sex);

            Console.Write("\nDate of Birth: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Date_of_Birth.txt"));
            Console.Write(") : ");
            string dob = _pa.ReadValidDate("DOB");
            if (dob != "")
                fields.Add("Date of Birth", dob);

            Console.Write("\nPhone Number: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Phone_Number.txt"));
            Console.Write(") : ");
            string phno = _pa.ReadValidPhNo("EDIT");
            if (phno != "")
                fields.Add("Phone Number", phno);

            Console.Write("\nEmail Address: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Email_Address.txt"));
            Console.Write(") : ");
            string email = Console.ReadLine();
            if (email != "")
                fields.Add("Email Address", email);

            if (fields.Count != 0)
            {
                Console.Write("\nPreviewing changes in ");
                int timer = 4;
                while (timer >= 0)
                {
                    Console.CursorLeft = 22;
                    Console.Write(timer);
                    timer--;
                    Thread.Sleep(800);
                }

                Console.WriteLine();
                _pa.PreviewOutput(fields);

                Console.WriteLine("\nDo you want to save changes? \nA - Yes \nB - No");
                string save = Console.ReadLine();
                save = save.ToUpper();
                while (!_pa.IsValid(save, 2))
                {
                    Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A or B");
                    save = Console.ReadLine();
                    save = save.ToUpper();
                }

                if (save == "A")
                    SaveData(fields, true, "contact", path.Split('\\')[2]);
                else
                {
                    Console.WriteLine("\n*****************************\nEDIT CONTACT MENU EXITED\n*****************************");
                    MainMenu();
                }
            }
            else
            {
                Console.WriteLine("\n*****************************\nNO CHANGES MADE \nEDIT CONTACT MENU EXITED\n*****************************");
                MainMenu();
            }
        }

        private void AddContacts()
        {
            Dictionary<string, string> fields = new Dictionary<string, string>();

            Console.CursorLeft = 37;
            _pa.WriteYellowText("ADD NEW CONTACT");
            Console.Write("\nNOTE: Fields with ");
            _pa.WriteRedText("*");
            Console.WriteLine(" are Compulsory\n      Press ENTER at any non-compulsory field to skip\n      When entering date, ensure month and day always have two numbers. \n");

            _pa.WriteRedText("*");
            Console.Write("First Name: \t");
            fields.Add("First Name", _pa.ReadValidComp());
            _pa.WriteRedText("\n*");
            Console.Write("Last Name: \t");
            fields.Add("Last Name", _pa.ReadValidComp());
            Console.Write("\nMiddle Name: \t");
            fields.Add("Middle Name", Console.ReadLine());
            Console.Write("\nAddress: \t");
            fields.Add("Address", Console.ReadLine());
            Console.Write("\nState: \t\t");
            fields.Add("State", Console.ReadLine());
            Console.Write("\nCountry: \t");
            fields.Add("Country", Console.ReadLine());
            Console.Write("\nGender: \t");
            fields.Add("Gender", _pa.ReadValidGender("ADD"));
            Console.Write("\nDate of Birth (YYYY-MM-DD): \t");
            fields.Add("Date of Birth", _pa.ReadValidDate("DOB"));
            _pa.WriteRedText("\n*");
            Console.Write("Phone Number: \t");
            fields.Add("Phone Number", _pa.ReadValidPhNo("ADD"));
            Console.Write("\nEmail Address: \t");
            fields.Add("Email Address", Console.ReadLine());

            Console.Write("\nPreviewing Contact in " + " ");
            int timer = 7;
            while (timer >= 0)
            {
                Console.CursorLeft = 22;
                Console.Write(timer);
                timer--;
                Thread.Sleep(800);
            }

            Console.WriteLine("\n");
            _pa.PreviewOutput(fields);

            Console.WriteLine("\nDo you want to save this contact? \nA - Yes \nB - No");
            string save = Console.ReadLine();
            save = save.ToUpper();
            while (!_pa.IsValid(save, 2))
            {
                Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A or B");
                save = Console.ReadLine();
                save = save.ToUpper();
            }

            if (save == "A")
                SaveData(fields, false, "contact");
            else
            {
                Console.WriteLine("\n*****************************\nADD CONTACT MENU EXITED\n*****************************");
                Contacts();
            }
        }

        private void SaveData(Dictionary<string, string> fields, bool issaved, string type, string sname = "")
        {
            string savename = "";
            if (!issaved)
            {
                Console.Write("\nEnter name to store " + type.ToLower() + " with: ");
                savename = _pa.ReadValidComp();

                savename = savename.Replace(" ", "");

                while (Directory.GetDirectories(@"PersonalAssistant\" + type + "s").Contains(@"PersonalAssistant\" + type + @"s\" + savename))
                {
                    Console.WriteLine("\n" + type.ToUpper() + " with this name already exists. Please enter another name.".ToUpper());
                    savename = _pa.ReadValidComp();
                }
            }
            else
                savename = sname;

            if (type.ToLower() == "appointment")
            {
                if (fields.ContainsKey("Date of Appointment"))
                {
                    File.WriteAllText(@"PersonalAssistant\AllDates\" + savename + ".txt", fields["Date of Appointment"]);
                }
            }

            Directory.CreateDirectory(@"PersonalAssistant\" + type + @"s\" + savename);
            try
            {
                foreach (var dt in fields)
                {
                    File.WriteAllText(@"PersonalAssistant\" + type + @"s\" + savename + @"\" + dt.Key.Replace(' ', '_') + ".txt", dt.Value);
                }

                Console.WriteLine("\n*****************************\n" + type.ToUpper() + " SUCCESFULLY SAVED\n*****************************");
                MainMenu();
            }
            catch (Exception e)
            {
                Console.WriteLine("\nAN ERROR OCCURED. " + e.Message);
                MainMenu();
            }
        }

        private void Appointments()
        {
            Console.WriteLine("\nPERSONAL ASSISTANT APPOINTMENTS MENU \nA - New \nB - Open \nC - View all \nD - Main Menu");
            string ans = Console.ReadLine();
            ans = ans.ToUpper();
            while (!_pa.IsValid(ans, 5))
            {
                Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A, B , C, D or E");
                ans = Console.ReadLine();
                ans = ans.ToUpper();
            }

            switch (ans)
            {
                case "A": Console.WriteLine(); AddMeetings(); break;
                case "B": OpenAppointments(); break;
                case "C": ViewAllAppointments(); break;
                case "D": MainMenu(); break;
                case "E": _pa.ExitApp(); break;
            }
        }

        private void AddMeetings()
        {
            Dictionary<string, string> fields = new Dictionary<string, string>();

            Console.CursorLeft = 36;
            _pa.WriteYellowText("ADD NEW APPOINTMENT");
            Console.Write("\nNOTE: Fields with ");
            _pa.WriteRedText("*");
            Console.WriteLine(" are Compulsory\n      Press ENTER at any non-compulsory field to skip\n      When entering date, ensure month and day always have two numbers. \n");

            _pa.WriteRedText("\n*");
            Console.Write("Subject: ");
            fields.Add("Subject", _pa.ReadValidComp());

            _pa.WriteRedText("\n*");
            Console.Write("Location: ");
            fields.Add("Location", _pa.ReadValidComp());

            _pa.WriteRedText("\n*");
            Console.Write("Date of Appointment: ");
            fields.Add("Date of Appointment", _pa.ReadValidDate("DOM"));

            _pa.WriteRedText("\n*");
            Console.Write("Time of Appointment: ");
            fields.Add("Time of Appointment", _pa.ReadValidTime(false));

            Console.Write("\nNotes: ");
            fields.Add("Notes", Console.ReadLine());

            Console.Write("\nPreviewing Appointment in " + " ");
            int timer = 3;
            while (timer >= 0)
            {
                Console.CursorLeft = 26;
                Console.Write(timer);
                timer--;
                Thread.Sleep(800);
            }

            Console.WriteLine("\n");
            _pa.PreviewOutput(fields);

            Console.WriteLine("\nDo you want to save this Appointment? \nA - Yes \nB - No");
            string save = Console.ReadLine();
            save = save.ToUpper();
            while (!_pa.IsValid(save, 2))
            {
                Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A or B");
                save = Console.ReadLine();
                save = save.ToUpper();
            }

            if (save == "A")
                SaveData(fields, false, "appointment");
            else
            {
                Console.WriteLine("\n*********************************\nADD APPOINTMENTS MENU EXITED\n*********************************");
                Appointments();
            }
        }

        private void OpenAppointments()
        {
            Console.CursorLeft = 35;
            _pa.WriteYellowText("OPEN APPOINTMENT MENU");
            Console.Write("\n\nEnter the name used to save the appointment: ");
            string savname = _pa.ReadValidComp();
            string upath = @"PersonalAssistant\Appointments\";

            savname = savname.Replace(" ", "");

            while (savname != "0" && !Directory.Exists(upath + savname))
            {
                Console.WriteLine("\nNAME DOESN'T EXIST. PLEASE ENTER A VALID NAME OR ENTER 0 TO EXIT AND USE VIEW ALL");
                savname = _pa.ReadValidComp();
            }

            if (savname == "0")
                Appointments();
            else
            {
                if (Directory.Exists(upath + savname))
                {
                    string subj = File.ReadAllText(upath + savname + @"\Subject.txt");
                    Console.WriteLine("\nAppointment (" + subj + ") Found \nWhat do you want to do? \nA - Edit \nB - View \nC - Delete \nD - Back to Main Menu");
                    string ac = _pa.ReadValidComp();
                    ac = ac.ToUpper();

                    while (!_pa.IsValid(ac, 4))
                    {
                        Console.WriteLine("\nYou have selected an invalid value. Please enter either A, B, C or D");
                        ac = _pa.ReadValidComp();
                    }

                    switch (ac)
                    {
                        case "A": EditAppointment(upath + savname + @"\"); break;
                        case "B": ViewAppointment(upath + savname + @"\"); break;
                        case "C": DeleteAppointment(upath + savname + @"\"); break;
                        case "D": MainMenu(); break;
                    }
                }
            }
        }

        private void EditAppointment(string path)
        {
            Dictionary<string, string> fields = new Dictionary<string, string>();

            Console.CursorLeft = 37;
            _pa.WriteYellowText("EDIT APPOINTMENT");
            Console.WriteLine("\nNOTE: Press ENTER at any field to skip editing\n      When entering date, ensure month and day always have two numbers. \n      Text shown in yellow indicates the existing data in that field");

            Console.Write("\nSubject: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Subject.txt"));
            Console.Write(") : ");
            string subject = Console.ReadLine();
            if (subject != "")
                fields.Add("Subject", subject);

            Console.Write("\nLocation: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Location.txt"));
            Console.Write(") : ");
            string location = Console.ReadLine();
            if (location != "")
                fields.Add("Location", location);

            Console.Write("\nDate of Appointment: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Date_of_Appointment.txt"));
            Console.Write(") : ");
            string doa = _pa.ReadValidDate("EDIT");
            if (doa != "")
                fields.Add("Date of Appointment", doa);

            Console.Write("\nTime of Appointment: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Time_of_Appointment.txt"));
            Console.Write(") : ");
            string toa = _pa.ReadValidTime(true);
            if (toa != "")
                fields.Add("Time of Appointment", toa);

            Console.Write("\nNotes: \t(");
            _pa.WriteYellowText(File.ReadAllText(path + "Notes.txt"));
            Console.Write(") : ");
            string state = Console.ReadLine();
            if (state != "")
                fields.Add("Notes", state);

            if (fields.Count != 0)
            {
                Console.Write("\nPreviewing changes in ");
                int timer = 3;
                while (timer >= 0)
                {
                    Console.CursorLeft = 22;
                    Console.Write(timer);
                    timer--;
                    Thread.Sleep(800);
                }

                Console.WriteLine();
                _pa.PreviewOutput(fields);

                Console.WriteLine("\nDo you want to save changes? \nA - Yes \nB - No");
                string save = Console.ReadLine();
                save = save.ToUpper();
                while (!_pa.IsValid(save, 2))
                {
                    Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A or B");
                    save = Console.ReadLine();
                    save = save.ToUpper();
                }

                if (save == "A")
                    SaveData(fields, true, "appointment", path.Split('\\')[2]);
                else
                {
                    Console.WriteLine("\n*****************************\nEDIT APPOINTMENT MENU EXITED\n*****************************");
                    MainMenu();
                }
            }
            else
            {
                Console.WriteLine("\n*****************************\nNO CHANGES MADE \nEDIT APPOINTMENT MENU EXITED\n*****************************");
                MainMenu();
            }
        }

        private void ViewAppointment(string path)
        {
            Console.CursorLeft = 33;
            _pa.WriteYellowText("APPOINTMENT DETAILS (" + path.Split('\\')[2] + ")");
            Console.Write("\n\nSubject: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Subject.txt"));
            Console.Write("\nLocation: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Location.txt"));
            Console.Write("\nDate of Appointment: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Date_of_Appointment.txt"));
            Console.Write("\nTime of Appointment: \t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Time_of_Appointment.txt"));
            Console.Write("\nNotes: \t\t");
            _pa.WriteYellowText(File.ReadAllText(path + @"Notes.txt"));

            Console.WriteLine();
            Appointments();
        }

        private void DeleteAppointment(string path)
        {
            Console.WriteLine("\nDo you really want to delete this appointment? \nA - Yes \nB - No");
            string inp = _pa.ReadValidComp();
            inp = inp.ToUpper();
            while (!_pa.IsValid(inp, 2))
            {
                Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A or B");
                inp = Console.ReadLine();
                inp = inp.ToUpper();
            }

            switch (inp)
            {
                case "A": Directory.Delete(path, true); File.Delete(@"PersonalAssistant\AllDates\" + path.Split('\\')[2] + ".txt"); Console.WriteLine("\n*****************************\nAPPOINTMENT DELETED SUCCESFULLY\n*****************************"); MainMenu(); break;
                case "B": Console.WriteLine("\n*****************************\nDELETE APPOINTMENT MENU EXITED\n*****************************"); MainMenu(); break;
            }
        }

        private void ViewAllAppointments()
        {
            Console.CursorLeft = 37;
            _pa.WriteYellowText("ALL APPOINTMENT NAMES\n\n");
            if (!Directory.EnumerateFileSystemEntries(@"PersonalAssistant\Appointments").Any())
            {
                Console.WriteLine("\nNO SAVED APPOINTMENTS FOUND");
                MainMenu();
            }
            else
            {
                foreach (string f in Directory.GetDirectories(@"PersonalAssistant\Appointments"))
                {
                    string names = f.Split('\\')[2];
                    names = names.First().ToString().ToUpper() + names.Substring(1);
                    Console.WriteLine(names);
                }

                Console.WriteLine("\nDo you want to open an appointment? \nA - Yes \nB - No");
                string inp = _pa.ReadValidComp();
                inp = inp.ToUpper();
                while (!_pa.IsValid(inp, 2))
                {
                    Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A or B");
                    inp = Console.ReadLine();
                    inp = inp.ToUpper();
                }

                switch (inp)
                {
                    case "A": OpenAppointments(); break;
                    case "B": MainMenu(); break;
                }
            }
        }

        private void Calendar()
        {
            Console.WriteLine("\nPERSONAL ASSISTANT CALENDAR \nA - This Month \nB - Enter Date \nC - Mainmenu");
            string ans = Console.ReadLine();
            ans = ans.ToUpper();
            while (!_pa.IsValid(ans, 3))
            {
                Console.WriteLine("\nINVALID SELECTION \nPLEASE SELECT A, B, or C");
                ans = Console.ReadLine();
                ans = ans.ToUpper();
            }

            switch (ans)
            {
                case "A": _pa.DisplayMonth(DateTime.Today.Month, DateTime.Today.Year); Calendar(); break;
                case "B": ShowCalendar(); break;
                case "C": MainMenu(); break;
            }
        }

        private void ShowCalendar()
        {
            Console.Write("\nEnter Year: ");
            string year = Console.ReadLine();
            int yearint = 0;
            while ((year.Length != 4 || !int.TryParse(year, out yearint)) && year != "0")
            {
                Console.WriteLine("\nENTERED AN INVALID YEAR. PLEASE ENTER A VALID YEAR OR 0 TO EXIT");
                year = Console.ReadLine();
            }

            if (year == "0")
                MainMenu();

            Console.WriteLine("\nSelect Month \n1 - January \n2 - February \n3 - March \n4 - April \n5 - May \n6 - June \n7 - July \n8 - August \n9 - September \n10 - October \n11 - November \n12 - December");
            string month = Console.ReadLine();
            int monthint = 0;
            while ((!int.TryParse(month, out monthint) || monthint > 12) && month != "0")
            {
                Console.WriteLine("\nSELECTED MONTH INVALID. PLEASE ENTER A VALID MONTH OR 0 TO EXIT");
                month = Console.ReadLine();
            }

            if (month == "0")
                MainMenu();

            _pa.DisplayMonth(monthint, yearint);
            MainMenu();
        }

        private void About()
        {
            Console.CursorLeft = 35;
            _pa.WriteYellowText("ABOUT PERSONAL ASSISTANT");
            Console.WriteLine("\n\nVersion - \t\t2.0.0 \nDevelopment Language - \tVisual C# 2015 \nWebsite - \t\thttp://personala.codeplex.com");
            Console.WriteLine("\nPersonal Assistant is a CUI application to store contacts and appointments.");
            Console.WriteLine("\nFeatures: ");
            Console.WriteLine("1 - Attractive interface for easy usage");
            Console.WriteLine("2 - Ability to edit and delete saved contacts and appointments.");
            Console.WriteLine("3 - Ability to view names of all saved contacts and appointments.");
            Console.WriteLine("4 - Calendar with ability to quickly view days of appointments");
            Console.WriteLine("5 - Open source code downloadable at http://personala.codeplex.com");

            Console.WriteLine("\nPress ENTER to return mainmenu");
            Console.ReadLine();
            MainMenu();
        }
    }
}